/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crypto;

import Model.User;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ryanradder
 */
public class Crypt {
    
    public Crypt(){
        
    }
   
        public static String encrypt(String to_encrypt){
        int length = to_encrypt.length();
        String result= "";
        char ch;
        for(int i = 0 ; i < length ; i++){
            ch = to_encrypt.charAt(i);
            if(i%2==0)
            {
                ch +=2;
            }else if(i%3==0){
                ch -=1;
            }
            else{
                ch -=5;
            }   
           result +=ch;
        }     
        return result;
    }
        
          public static String hash(String password) {
        String result;

        MessageDigest m;
        try {
            m = MessageDigest.getInstance("MD5");
            m.reset();
            m.update(password.getBytes());
            byte[] digest = m.digest();
            BigInteger bigInt = new BigInteger(1, digest);
            String hashtext = bigInt.toString(16);
            // Now we need to zero pad it if you actually want the full 32 chars.
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            result = hashtext;
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(User.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
            return null;
        }
   
        return result;
    }
        
    
    
}
